<template>
  <div class="top-bar-main-container" :class="{show: $store.state.direction <= 0}">
    <div>
      <top-bar-left></top-bar-left>
        <top-bar-center :menus="menus" :class="{show : $store.state.direction <= 0}"></top-bar-center>
      <top-bar-right :user="user"></top-bar-right>
    </div>
  </div>
</template>

<script>
import topBarLeft from '@/components/top-bar/childComponments/left'
import topBarRight from '@/components/top-bar/childComponments/right'
import topBarCenter from '@/components/top-bar/childComponments/center'

export default {
  name: 'topBar',
  data () {
    return {
      isShow: true,
      menus: [],
      user: {}
    }
  },
  methods: {
    showChange () {
      this.isShow = !this.isShow
    },
    getDetail () {
      this.$http.homeMenu().then((res) => {
        if (res && res.code === 200) {
          const data = res.data
          this.menus = data.menus
          this.user = data.user
          this.$message({
            message: res.msg,
            type: 'success'
          })
        } else {
          this.user = {}
          this.menus = undefined
          let msg = res ? (res.msg ? res.msg : '未知错误') : '未知错误'
          this.$message({
            message: msg,
            type: 'warning'
          })
        }
      }).catch((err) => {
        this.$message({
          message: '数据获取异常,请检查网络连接，稍后重试。',
          type: 'warning',
          duration: 2000
        })
      })
    }
  },
  components: {
    topBarLeft,
    topBarRight,
    topBarCenter,
  },
  created () {
    this.getDetail()
  }
}
</script>

<style scoped lang="scss">
.top-bar-main-container {
  position: fixed;
  z-index: 9999;
  top: 0;
  left: 0;
  right: 0;
  width: 100vw;
  height: 80px;
  line-height: 80px;

  &:hover {
    .center {
      display: block;
    }

    background: #fff;
    transition: all 1.5s;
  }
}
.show {
  display: block;
  background-color: #fff;
}

</style>
<style scoped>
/* 样式覆盖 */
::v-deep .el-menu.el-menu--horizontal {
  border-bottom: 0px !important;
}

::v-deep .el-menu--horizontal > .el-menu-item.is-active {
  border-bottom: 0px !important;
}

::v-deep .el-menu {
  background-color: transparent !important;
  transition: background-color 1.5s;
}
</style>